package cn.credit.ms.controller;

import cn.credit.ms.mapper.DtBatchTxnMapper;
import cn.credit.ms.model.TUser;
import cn.credit.ms.service.RedisService;
import cn.credit.ms.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@Slf4j
public class UserController {


    @Autowired
    private DiscoveryClient discoveryClient;

    @Autowired
    private UserService userService;

    @Autowired
    private RedisService redisService;


    @Autowired
    private DtBatchTxnMapper dtBatchTxnMapper;

    @Value("${rest.value}")
    private String value;


    @GetMapping("/rest")
    public String test01() {
        return value;
    }

    @GetMapping("/mybatis/{id}")
    public List<TUser> test02(@PathVariable Long id) {
        log.info("ceshi");
//        log.info(JSON.toJSONString( dtBatchTxnMapper.selectByPrimaryKey(123L)));
        return userService.getList(id);
    }

    @GetMapping("/redis")
    public String test03() {
        return redisService.get("test");
    }


    @RequestMapping(value = "/callback", method = { RequestMethod.POST, RequestMethod.GET })
    public String loginByPost2(@RequestBody String body) {
        System.out.println("回调数据:"+body);
        return body;
    }

}
